<template>
  <div>

    <div v-show="pdata.bshow_smartword" class="panel wrapper news_detail">
      <h3 v-show="pdata.content" >{{pdata.content.title}}</h3>
      <div v-show="pdata.bshow_kw" class="row">
        <div class="col-md-12">
          <span v-for="item in pdata.content_kw">
            <code class="bg-info">{{item.word}}</code>&nbsp;
          </span>
        </div>
      </div>
      <div class="row">
        <ul v-show="pdata.bshow_sa" class="news_tag news_tag_inlist" v-class="pdata.sa_tag">
          <li class="t1"><span>{{pdata.name_sa}}</span><i></i></li>
          <li class="t2"><span>{{pdata.name_sa}}</span><i></i></li>
          <li class="t3"><span>{{pdata.name_sa}}</span><i></i></li>
          <li class="t4"><span>{{pdata.name_sa}}</span><i></i></li>
          <li class="t5"><span>{{pdata.name_sa}}</span><i></i></li>
        </ul>
        <div class="news_info">
          <a href="#" data-toggle="tooltip" data-placement="left" v-bind:title="pdata.score_sa">
            情感分</a>
        </div>
      </div>

      <div class="news_tips">
        来源：{{pdata.content.author}}  时间：{{pdata.content.time}}
      </div>

      <div id="summary" class="summary_block" v-show="pdata.bshow_se">
      	<span v-for="se in pdata.content_se">
      		{{se.sentence}}。
      	</span>
     	</div>
    	<p class="news_txt" v-html="pdata.content_sw"></p>
    </div>

  </div>

</template>

<script>
//import {
//  getioc_data
//} from 'api/ai/zx/index';

import { getioc_data} from '@/api/zx';

  export default {
    data: function(){
      return {
         pdata:  {
          bshowcontrol: false, //true,

          bshow_smartword: false,
          content_sw: null,

          bshow_se: false,
          content_se: null,

          bshow_kw: false,
          content_kw: null,

          // 情感分析
          score_sa : 0.00,
          bshow_sa : false,
          name_sa: '中性',
          sa_type: 0,
          sa_tag: 'news_tag3',

          content: { title: '',author:'',time:''},
          bshowcontext: false,
          bshowresult : false,
          listcontents: null,

          strcontent_text: null,
          strtitle_text: null,
        },
         vc: {
           submitting: false
         },
       }
    },
    created(){
        this.load_detail();
    },
    computed: {
      /*
        data(){
            const self = this;
            return self.tableData;
          }
          */
    },
    methods: {
      load_detail() {
         let self = this;
         if (this.$route.params.id  == undefined ||
             this.$route.params.id  == null) {
               return null;
         }
           // process
         self.pdata.submitting = true;
         //self.arr_tablehead = self.arr_tablehead_fixed
         // 查询具体内容：strjson = '{"SRVC_ID":"9920","type":"2","id":"c7a9ea0cafe811e788c9a5692fece266"}'
         var qdata = {
                       //SRVC_ID:"9954",
                       SRVC_ID: "90101010",
                       id:this.$route.params.id
                     };
         getioc_data(qdata).then(response => {
           var sdata = response;
           self.pdata.content = sdata._source;
           console.log(self.pdata.content);
           var strcontent = self.pdata.content.content;
           self.pdata.strcontent = strcontent;

           self.pdata.strtitle_text = self.pdata.content.title;
           var strcontent_text = self.pdata.content.content_text;
           console.log('content_text',strcontent_text);
           self.pdata.strcontent_text = strcontent_text;
           //self.load_smartword();
           self.pdata.content_sw = self.pdata.content.content;
           self.pdata.bshow_smartword = true;
           self.pdata.content_se = self.pdata.content.content_ses;
           self.pdata.bshow_se = true;

           self.pdata.content_kw = self.pdata.content.content_kw;
           self.pdata.bshow_kw = true;
           self.pdata.score_sa = sdata._score;
           self.pdata.sa_tag = 'news_tag3';
           self.pdata.sa_type = 0;
           if (self.pdata.score_sa >3.0){
                self.pdata.sa_type = 1;
                self.pdata.name_sa = '利好';
                self.pdata.sa_tag = 'news_tag2';

           }
           else if (self.pdata.score_sa <=3.0){
                self.pdata.sa_type = -1;
                self.pdata.name_sa = '利差';
                self.pdata.sa_tag = 'news_tag4';
           }
           self.pdata.bshow_sa = true;
           self.msgError = null;
         })

      },
      load_smartword() {
         let Base64 = require('js-base64').Base64;
         let self = this;
         var strcontent = self.pdata.strcontent;
         //strcontent_text;
         var pysrc_base64 = Base64.encode(strcontent);

         var strtitle = self.pdata.strtitle_text;
         var title_base64 = Base64.encode(strtitle);

         var strbasetext = self.pdata.strcontent_text;
         var basetext_base64 = Base64.encode(strbasetext);



         var qdata = {
                       SRVC_ID:"9951",
                       title:title_base64,
                       basetext:basetext_base64,
                       text:pysrc_base64
                     };
         getioc_data(qdata).then(response => {
               var data = response;
               console.log('9951',data);
               self.pdata.content_sw = data.content;
               self.pdata.bshow_smartword = true;

               self.pdata.content_se = data.sentences;
               self.pdata.bshow_se = true;

               self.pdata.content_kw = data.keywords;
               self.pdata.bshow_kw = true;

               self.pdata.score_sa = data.score;
               self.pdata.sa_tag = 'news_tag3';
               self.pdata.sa_type = 0;
               if (self.pdata.score_sa >3.0){
                  self.pdata.sa_type = 1;
                  self.pdata.name_sa = '利好';
                  self.pdata.sa_tag = 'news_tag2';

               }
               else if (self.pdata.score_sa <=3.0){
                 self.pdata.sa_type = -1;
                 self.pdata.name_sa = '利差';
                 self.pdata.sa_tag = 'news_tag4';
               }
               self.pdata.bshow_sa = true;
               self.msgError = null;
           }) // post over
         } //function load_smartword
      } // methods
 } // export default
</script>

<style scoped>

.news_tag {
    width: 100%;
    overflow: hidden;
}

.news_tag li {
    float: left;
    background: transparent!important;
}

.news_tag li span {
    float: left;
    height: 16px;
    line-height: 16px;
    padding: 0 6px;
    font-size: 9px;
    color: #fff;
    display: none;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    vertical-align: middle;
}

.ios .news_tag li span {
    padding-top: 1px;
}

.news_tag li i {
    float: left;
    width: 28px;
    height: 6px;
    margin-top: 5px;
}

.news_tag li.t1 span,
.news_tag li.t1 i {
    background-color: #2a8e29;
}

.news_tag li.t2 span,
.news_tag li.t2 i {
    background-color: #4cba2a;
}

.news_tag li.t3 span,
.news_tag li.t3 i {
    background-color: #c5d106;
}

.news_tag li.t4 span,
.news_tag li.t4 i {
    background-color: #ff9800;
}

.news_tag li.t5 span,
.news_tag li.t5 i {
    background-color: #ea4410;
}

.news_tag li.t1 i {
    border-radius: 7px 0 0 7px;
}

.news_tag li.t5 i {
    border-radius: 0 7px 7px 0;
}

.news_tag li.on span {
    display: block;
}

.news_tag li.on i {
    display: none;
}

.news_tag_inlist {
    float: left;
    width: auto;
    padding-top: 2px;
}

.news_tag1 li.t5 span,
.news_tag2 li.t4 span,
.news_tag3 li.t3 span,
.news_tag4 li.t2 span,
.news_tag5 li.t1 span {
    display: block;
}

.news_tag1 li.t5 i,
.news_tag2 li.t4 i,
.news_tag3 li.t3 i,
.news_tag4 li.t2 i,
.news_tag5 li.t1 i {
    display: none;
}

/*================information detail page=========================*/

.news_detail {
    padding: 20px;
}

.news_detail h3 {
    // font-size: 20px;
    font-weight: bold;
    margin-bottom: 10px;
    color: #2f2824;
}

.news_detail .news_tag {
    margin-right: 30px;
}

.news_info {
    float: left;
    color: rgba(103, 89, 82, .5);
    font-size: 14px;
    margin: 0 0 0 0;
    position: relative;
    top: -1px;
}

.summary_block {
    background-color: #f4f3f2;
    color: #675952;
    font-size: 17px;
    line-height: 1.8;
    text-indent: 30px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    padding: 13px 16px;
    position: relative;
    margin-bottom: 16px;
    -ms-word-break: break-all;
    word-break: break-all;
    border-radius: 0 3px 3px;
    text-align: justify;
    clear: both;
}

.summary_block:before {
    content: "";
    display: inline-block;
    position: absolute;
    left: 0;
    top: 0;
    border-radius: 0 3px 3px 0;
    background-color: #ff9800;
    color: #fff;
    z-index: 10;
    text-indent: 0;
    font-size: 12px;
    padding: 0 4px;
    line-height: 1.6
}

.news_tips {
    color: #000;
    font-size: 12px;
    padding: 5px 2px;
}

.news_txt {
    color: #000;
    font-size: 17px;
    line-height: 1.8;
    padding-bottom: 32px;
    clear: both;
}

.news_txt p,
.news_txt div {
    margin-bottom: 18px;
    word-break: break-all;
}


</style>
